package com.zhiwei.most.wear.widget;

/**
 * Create by zhiweizhu on 2022/3/1
 */

import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

public class ScalingScrollLayoutCallback extends WearableLinearLayoutManager.LayoutCallback {

    /** How much should we scale the icon at most. */
    private static final float MAX_ICON_PROGRESS = 0.65f;

    @Override
    public void onLayoutFinished(View child, RecyclerView parent) {

        // Figure out % progress from top to bottom.
        float centerOffset = (child.getHeight() / 2.0f) / parent.getHeight();
        float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset;

        // Normalize for center.
        float progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset);

        // Adjust to the maximum scale.
        progressToCenter = Math.min(progressToCenter, MAX_ICON_PROGRESS);

        child.setScaleX(1 - progressToCenter);
        child.setScaleY(1 - progressToCenter);
    }
}